let v = new Vue({
    el:'#main-container',
    data:{
        user:{

        }
    },
    methods:{
        initUserLook:function () {
            axios({
                url:'main/sidenav/getLoginUser',
            }).then(resp => {
                this.user = resp.data.obj;
                if(this.user.isSecret === '1'){
                    this.user.isSecret = false;
                }else {
                    this.user.isSecret = true;
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        updatePersonal:function () {
            if(this.user.isSecret){
                this.user.isSecret = 0;
            }else{
                this.user.isSecret = 1;
            }
            axios({
                url:'main/user/updatePersonal',
                method:'put',
                data:this.user,
            }).then(resp => {
                layer.msg(resp.data.msg);
                if(!resp.data.success){
                    this.initUserLook();
                }
            }).catch(error => {
                layer.msg(resp.data.msg);
            })
        },
        uploadImg:function (e) {
            let formData = new FormData();
            let file = e.target.files[0];
            formData.append("file",file);

            axios({
                url:'main/user/upload',
                data:formData,
                method: 'post',
                header:{'content-type':'multipart/form-data'}
            }).then(resp => {
                layer.msg("上传成功");
                this.user.pic = resp.data.obj;
                $("#headImg").attr("src",this.user.pic);
            }).catch(error => {
                layer.msg(error);
            })
        }
    },
    created:function () {
        this.initUserLook();
    }
})